package main

import (
	"encoding/json"
	"fmt"
)

type Student struct {
	ID     int
	Gender string
	name   string // //私有属性不能被 json 包访问
	Sno    string
}

func main() {
	var s1 = Student{
		ID:     1,
		Gender: "男",
		name:   "李四",
		Sno:    "s0001",
	}

	fmt.Println(s1)

	var s, err = json.Marshal(s1)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(s))

	var s2 = Student{}
	fmt.Println(s2)
	fmt.Println(json.Marshal(s2))
	err2 := json.Unmarshal(s, &s2)
	if err2 != nil {
		fmt.Println(err2)
	}

	var s3, _ = json.Marshal(s2)
	fmt.Println(string(s3))
}
